package com.be.beadmin.service.event;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

/**
 *  @Description 监听系统关闭事件
 */
public class ShutdownListener implements EventListener {
	
	private Logger logger = LoggerFactory.getLogger(this.getClass());

	@Override
	public void onEvent(Event event) {
		if (!(event instanceof ShutdownEvent)) {
			return;
		}
		ShutdownEvent e = (ShutdownEvent) event;
		// 事件源
		String source = e.getSource();
		
		logger.warn("监听到系统关闭事件，事件源：[ {} ]，系统即将关闭", source);
		
		// 关闭HTTP连接池
//		HttpClientFactory.getInstance().close();
		
		try {
			TimeUnit.SECONDS.sleep(1);
		} catch (InterruptedException e1) {
			logger.error("系统关闭", e1);
		}
		// 关闭进程
		Runtime.getRuntime().exit(0);
	}
}
